package mystack;

import java.util.Arrays;

/**
 * Created with Intellij IDEA.
 * Description;
 * User:墨琦
 * Data:2023-04-12
 * Time:8:59
 */
public class MyStack<T> {

     public  T[] elem= (T[]) new Object[10];
     public int size=0;
     MyStack()
     {}
    MyStack(int num)
    {
        size=num;
    }
     public void push(T num)
     {
         if(size== elem.length)
         {
             elem= Arrays.copyOf(elem,2*elem.length);
         }
         elem[size]=num;
         size++;
     }
     public T[] show(T[] elem,int size)
     {
         if(size<0)
         {
            return  null;
         }
         System.out.print(elem[size]+" ");
         return show(elem,size-1);
     }
     //将栈顶元素出栈并返回
     public T pop()
     {
         return elem[--size];
     }
     //
     public T peek()
     {
        return elem[size-1];
    }
    public boolean empty()
    {
        return size==0;
    }

}
